global_defs {
  notification_email {
  }
  router_id LVS_DEVEL
  vrrp_skip_check_adv_addr
  vrrp_garp_interval 0
  vrrp_gna_interval 0
  enable_script_security
}

{% for instance in combined_vars.keepalived_vrrp_instances %}
{% if instance.check is truthy %}
vrrp_script chk_{{ instance.name | lower }} {
  script "{{ instance.check.script }}"
  interval "{{ instance.check.interval | default(2) }}"
  weight "{{ instance.check.weight | default(2) }}"
}
{% endif %}

vrrp_instance {{ instance.name }} {
  state {{ instance.state | default('BACKUP') }}
  interface {{ instance.interface }}
  virtual_router_id {{ loop.index }}
  priority {{ global_bond_ip | split('.') | last }}
  advert_int 1

  authentication {
    auth_type {{ instance.auth.type }}
    auth_pass {{ instance.auth.pass }}
  }

  virtual_ipaddress {
    {{ instance.vip }}/24
  }

  unicast_src_ip {{ global_bond_ip }}

  unicast_peer {
{% for host in ansible_play_hosts if host != global_bond_ip %}
    {{ host }}
{% endfor %}
  }

  track_script {
    chk_{{ instance.name | lower }}
  }
}

{% endfor %}